import reducer from '../reducers/todoList.js';
import { ADD_TODO, CHANGE_CHECKBOX, REMOVE_TODO } from '../actions/todoList.js';

export default (ctx) => {
    const {
        changeCheckbox,
        removeTodo,
        addTodo
    } = reducer(ctx.$data);

    return function (type, ...args) {
        switch (type) {
            case ADD_TODO:
                addTodo(...args);
                break;
            case CHANGE_CHECKBOX:
                ctx.tdData = changeCheckbox(...args);
                break;
            case REMOVE_TODO:
                ctx.tdData = removeTodo(...args);
                break;
            default:
                break;
        }
    }
}